/**
 *@param {Array} position = [114.30,30.50]
 *@param {Array} attr =[{name:"xxx",type:"xxx",value:"xx"}]
 *@param {Object} service = {name:"ig-server服务的名称",layerId:"layerIndex"}
 *@param {Object} docLayer  地图文档图层
 *   */
 const PONT_STYLE = {
    Angle: 0,
    Color: 11, //子图的颜色
    Space: 0,
    SymHeight: 8,
    SymID: 1, //子图号
    SymWidth: 8,
  };
  const PONT_STYLE1 = {
    Angle: 0,
    Color: 6, //子图的颜色
    Space: 0,
    SymHeight: 5,
    SymID: 21, //子图号
    SymWidth: 5,
  };
  const PONT_STYLE2 = {
    Angle: 0,
    Color: 90, //子图的颜色
    Space: 0,
    SymHeight: 5,
    SymID: 21, //子图号
    SymWidth: 5,
  };
  const PONT_STYLE3 = {
    Angle: 0,
    Color: 4, //子图的颜色
    Space: 0,
    SymHeight: 5,
    SymID: 21, //子图号
    SymWidth: 5,
  };
class Point {
    /* 增删改查 */
    static add({
        position,
        service,
        attr = [],
        docLayer
    }) {
        var gpoint = new Zondy.Object.GPoint(position[0], position[1]);//createPoint();
        //设置当前点要素的几何信息
        var fGeom = new Zondy.Object.FeatureGeometry({ PntGeom: [gpoint] });
        // 根据attr中的数据设置点要素的属性信息

        //描述点要素的符号参数信息
        var pointInfo;
        if(attr[7].value === 0){
            pointInfo = new Zondy.Object.CPointInfo(PONT_STYLE1);
        }else if(attr[7].value === 1){
            pointInfo = new Zondy.Object.CPointInfo(PONT_STYLE2);
        }else if(attr[7].value === 2){
            pointInfo = new Zondy.Object.CPointInfo(PONT_STYLE3);
        }else{
            pointInfo = new Zondy.Object.CPointInfo(PONT_STYLE);
        }
        //设置当前点要素的图形参数信息
        var webGraphicInfo = new Zondy.Object.WebGraphicsInfo({
            InfoType: 1,
            PntInfo: pointInfo
        });
        //设置添加点要素的属性信息        
        var attValue = attr.map(item => item.value);

        //创建一个要素
        var feature = new Zondy.Object.Feature({ fGeom: fGeom, GraphicInfo: webGraphicInfo, AttValue: attValue });
        //设置要素为点要素
        feature.setFType(1);
        /* 2、创建数据集 */
        var featureSet = new Zondy.Object.FeatureSet();
        //设置属性结构
        /* 和mapgis中的图层的字段映射 */
        var cAttStruct = new Zondy.Object.CAttStruct({
            FldName: attr.map(item => item.name),
            FldNumber: 1,
            FldType: attr.map(item => item.type)
        });
        featureSet.AttStruct = cAttStruct;
        //添加要素到要素数据集
        /* addFeature addFeatures */
        featureSet.addFeature(feature);
        /* 学套路 学概念 */
        /* 3、向地图文档中的某一个图层添加 */
        /* http-post */
        var editService = new Zondy.Service.EditDocFeature(service.name, service.layerId, {

        });
        //执行添加点要素功能
        // editService.add(featureSet, function (data) {

        // });
        editService.add(featureSet, this.onPntSuccess(docLayer));
    }
    /* update attr必选项*/
    static update({
        position = [],
        attr = [],
        fid,
        service,
        docLayer,
        color = null
    }) {
        let fGeom = null;
        if (position.length) {
            var gpoint = new Zondy.Object.GPoint(position[0], position[1]);
            fGeom = new Zondy.Object.FeatureGeometry({ PntGeom: [gpoint] });
        }
        //设置添加点要素的图形参数信息
        let webGraphicInfo = null;
        if (color) {
            var pointInfo = new Zondy.Object.CPointInfo({
                Angle: 0,
                Color: color, //颜色
                Space: 0,
                SymHeight: 6,
                SymID: 21,//子图号
                SymWidth: 6
            });
            //设置当前点要素的图形参数信息
            webGraphicInfo = new Zondy.Object.WebGraphicsInfo({
                InfoType: 1,
                PntInfo: pointInfo
            });
        }


        //设置添加点要素的属性信息
        var attValue = attr.map(item => item.value);


        //创建一个点要素
        var newFeature = new Zondy.Object.Feature({
            fGeom: fGeom,
            GraphicInfo: webGraphicInfo,
            AttValue: attValue
        });
        //设置要素为点要素
        newFeature.setFType(1);
        newFeature.setFID(fid);
        /* 设置要素集 */
        var featureSet = new Zondy.Object.FeatureSet();
        //设置属性结构
        var cAttStruct = new Zondy.Object.CAttStruct({
            FldName: attr.map(item => item.name),
            FldNumber: attr.length,
            FldType: attr.map(item => item.type)
        });
        featureSet.AttStruct = cAttStruct;
        //添加要素到要素数据集
        featureSet.addFeature(newFeature);
        //创建一个编辑服务类
        var editService = new Zondy.Service.EditDocFeature(service.name, service.layerId, {

        });
        editService.update(featureSet, this.onPntSuccess(docLayer));
    }
    static onPntSuccess(docLayer) {
        return function (data) {
            console.log(data)
            if (data.succeed) {
                alert("操作要素成功！");
                docLayer.refresh();
            } else {
                alert("操作要素失败！");
            }
        }
    }
}
export { Point }